<?php
/**
 *  @author: Pham Van Diep
 *  @date:   18/2/2014
 *  @status: 0-> inactive
 *           1->active
 *           2->delete ( not delete out database)
 * 
 **/

if( !isset($AppUI) || 
	!isset($_SESSION['club'])
) {
	redirect(HOST_BACKEND);
}
$intAction 		= $this->input->post('paction', 0);

$arrClubId 	= $this->input->post('pclubid', null);
$strError		= '';
$strMsg			= '';
if($intAction && $arrClubId) {
	switch ($intAction) {
		case 1: // active
			if(isset($_SESSION['club']) && ($_SESSION['club']&1<<5) != 0) {							
				foreach($arrClubId as $row) {
                    //echo $row;
					$intError  = $this->club->updateStatus($AppUI->id,$row,1,1<<2);
				}
				$strMsg		= $arrMessage['club_update'];
			}
			else {
				$strError	= $arrError['noperm_club_update'];
			}
			break;        
		case 2: // delete
			if(isset($_SESSION['club']) && ($_SESSION['club']&1<<3) != 0) {				
				foreach($arrClubId as $row) {
					$this->club->updateStatus($AppUI->id,$row,2,1<<3);
				}
				$strMsg		= $arrMessage['club_delete'];
			}
			else {
				$strError	= $arrError['noperm_club_delete'];
			}
			break;	
       
		case 4: // delete database
			if(isset($_SESSION['club']) && ($_SESSION['club']&1<<3) != 0 && $AppUI->type == ROLE_ROOT) {
				foreach($arrClubId as $row) {
					$this->club->delete($AppUI->id,$row);
				}
				$strMsg		= $arrMessage['club_delete'];
			}
			else {
				$strError	= $arrError['noperm_club_delete'];
			}
			break;
         case 6: // inactive
        	if(isset($_SESSION['club']) && ($_SESSION['club']&1<<5) != 0) {	                			
				foreach($arrClubId as $row) {
					$ret = $this->club->updateStatus($AppUI->id,$row,0,1<<2);                    
				}
				$strMsg		= $arrMessage['club_inactive'];
			}
			else {
				$strError	= $arrError['noperm_club_inactive'];
			}
			break;	
		default:
            break;
		
	}
} else {
	$strError	= $arrError['nodata_act'];
}
if($strError == '') {
	CI_Function::setMsg($strMsg);
} else {
	CI_Function::setError($strError);	
}
redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND);

